package test.data_structure.linked_list;

import test.data_structure.stack.Stack;

public class LinkedListStack<T> implements Stack<T> {

    private LinkedList<T> list;

    public LinkedListStack() {
        list = new LinkedList<>();
    }

    @Override
    public int getSize() {
        return list.getSize();
    }

    @Override
    public boolean isEmpty() {
        return list.isEmpty();
    }

    @Override
    public void push(T data) {
        list.addFirst(data);
    }

    @Override
    public T pop() {
        return list.removeFirst();
    }

    @Override
    public T peek() {
        return list.getFirst();
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("Stack: top ");
        sb.append(list);
        return sb.toString();
    }

    public static void main(String[] args) {
        LinkedListStack<Integer> myStack = new LinkedListStack<>();
        for (int i = 0 ; i < 5 ; i++) {
            myStack.push(i);
            System.out.println(myStack);
        }
        myStack.pop();
        System.out.println(myStack);
    }

}
